<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		
		<form method="get" id="editForm" enctype="application/x-www-form-urlencoded">
			
			角色名称：<input type="text" name="roleName" id="edit_roleName" >
			
			<br />
			角色备注：<input type="text" name="roleRemark" id="edit_roleRemark" >
			
			<br/>
			 
			
			<input type="button" value="保存" id="btnAdd">
			
		</form>
		
		<script src="../assets/js/jquery.min.js"></script>
		<script>
			
			$(function(){
				
				
				
				 $("#btnAdd").click(saveForm);
				
				
			});
			
			function saveForm(){
				 
				 // console.log("手动去收集，当参数多了就麻烦了，不建议使用");
				// let params={};
				// params["roleName"]=$("#edit_roleName").val();
				// params["roleRemark"]=$("#edit_roleRemark").val();								 
				// console.log(params);
				
				
				
				console.log("自动收集数据，叫做  序列化------");
				let params2=$("#editForm").serialize();
				console.log(params2);			
		 
				//向后台提交数据
				$.ajax({
					type:"post",
					url:'http://localhost:8080/api/role/add',
					data:params2,  //变为  roleName=?&roleRemarke=?
					dataType:"json",
					success:function(resp){
						console.log(resp);
						if(resp.code===0){
							window.location.href="index-bootstrap.html";
						}else{
							alert(resp.message);
						}
					}
				});
				
			}
			
			
		</script>
	</body>
</html>
